<!-- Use preprocessors via the lang attribute! e.g. <template lang="pug"> -->
  <template>
    <div class="clock">
      <div class="clock-time">{{ time }}</div>
      <div class="clock-date">
        <span class="date">{{ `${date.solarYear}年${date.solarMonth}月${date.solarDay}日` }}</span>
        <span class="week">{{ date.ncWeek }}</span>
        <span class="week">{{ `农历${date.lunarMonth}月${date.lunarDay}日` }}</span>
        <span class="week">{{ date.gzYear }}年</span>
        <span class="week">{{ date.zodiac }}</span>
      </div>
    </div>
  </template>

<script>
import calendar from 'solarday2lunarday'

export default {
  name: 'clock',
  components: {},
  data () {
    return {
      time: '',
      date: '',
      week: '',
      timerHelper: false
    }
  },
  created () {
    this.updateTime()
    this.timerHelper = setInterval(this.updateTime, 1000)
  },
  beforeDestroy () {
    if (this.timerHelper) {
      clearInterval(this.timerHelper)
      this.timerHelper = false
    }
  },
  methods: {
    zeroPadding (num, digit) {
      let zero = ''
      for (let i = 0; i < digit; i++) {
        zero += '0'
      }
      return (zero + num).slice(-digit)
    },
    updateTime () {
      const cd = new Date()
      this.date = calendar.solar2lunar(+cd)
      this.time =
          this.zeroPadding(cd.getHours(), 2) +
          ':' +
          this.zeroPadding(cd.getMinutes(), 2) +
          ':' +
          this.zeroPadding(cd.getSeconds(), 2)
    }
  }
}
</script>

  <!-- Use preprocessors via the lang attribute! e.g. <style lang="scss"> -->
<style lang="scss" scoped>
  .clock {
    color: #fff;
    text-align: center;
    text-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    line-height: 1;
    margin-top: 30px;
  }
  .clock-time {
    letter-spacing: 2px;
    font-size: 95px;
  }
  .clock-date {
    letter-spacing: 2px;
    font-size: 12px;
    margin-top: 20px;
    line-height: 1;
    span {
      margin: 0 5px;
    }
  }
</style>
